<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8" %>
<%@ page import="jsp.util.ConnectionContext" %>
<%@ page import="java.io.*" %>
<%@ page import = "java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title></title>
<style type = "text/css">
	body {
		background-image: url(http://192.168.43.74:8080/PBGServer/img/3.PNG);
		background-image: no-repeat;
		background-attachment: fixed;
		background-position: center top;
	}
</style>
</head>
<body>
<center>
<%
request.setCharacterEncoding("utf8");

try{
	Connection conn = ConnectionContext.getConnection();
	Statement stmt = conn.createStatement();

	int lastRow = 0;
	String strSQL = "SELECT count(*) FROM pbgametable";
	ResultSet rs = stmt.executeQuery(strSQL);
	if (rs.next())
		lastRow = rs.getInt(1);
	rs.close();
	
	if(lastRow > 0){	
		rs = stmt.executeQuery("SELECT * FROM pbgametable order by time");		
		String name;
		int time;
%>
<br>
<h2>Ranking</h2>
	<table border = "1" bordercolor="black" cellpadding="10" cellspacing="0">
		<tr align = "center" bgcolor="lightblue">
			<td>순위</td>
			<td>닉네임</td>
			<td>소요시간</td>
		</tr>
<%	
		for(int i = 1 ; i < 6 ; i++){
			if(rs.next()){			
				name = rs.getString("name");
				time = rs.getInt("time");
				out.println("<tr align='center' bgcolor ='#E8FFFF'>");	
				out.println("<td>" + i + "</td>");
				out.println("<td>" + name + "</td>");
				if(time < 60){
					out.println("<td>" + time + "초</td>");
				}else{
					int min, sec;
					min = time / 60;
					sec = time % 60;
					out.println("<td>" + min + "분 " + sec + "초</td>");
				}
				out.println("</tr>");
			}
		}
	}else{
		%><br><br><br><br><br><br><br><br><%
		out.println("랭킹에 등록된 사용자가 아직 없습니다.");
	}%>
</table>
<%
	rs.close();
	stmt.close();
}catch(SQLException ex){
%>
에러: <%=ex %>
<% 
}
%>
</center>
</body>
</html>